package com.autumn.zero.workflow.constants;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import com.autumn.common.api.domain.values.IntegerConstantItemValue;

/**
 * 任务常量
 * 
 * @author 杨昌国 2019-01-28 18:44:02
 */
public class ProcessTaskConstants implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2502002788673366967L;

	/**
	 * 同意
	 */
	public static final int AGREE = 1;

	/**
	 * 拒绝
	 */
	public static final int REFUSE = 2;

	/**
	 * 撤回
	 */
	public static final int WITHDRAW = 3;

	/**
	 * 未知
	 */
	public static final int UNKNOWN = 99;

	private static final Map<Integer, IntegerConstantItemValue> NAME_MAP = new HashMap<>();

	static {
		NAME_MAP.put(AGREE, new IntegerConstantItemValue(AGREE, "通过", ""));
		NAME_MAP.put(REFUSE, new IntegerConstantItemValue(REFUSE, "拒绝", ""));
		NAME_MAP.put(WITHDRAW, new IntegerConstantItemValue(WITHDRAW, "撤回", ""));
		NAME_MAP.put(UNKNOWN, new IntegerConstantItemValue(UNKNOWN, "未知", ""));
	}

	/**
	 * 是否存在
	 * 
	 * @param value 值
	 * @return
	 */
	public static boolean exist(Integer value) {
		if (value == null) {
			return false;
		}
		return NAME_MAP.containsKey(value);
	}

	/**
	 * 获取名称
	 * 
	 * @param value 值
	 * @return
	 */
	public static String getName(Integer value) {
		IntegerConstantItemValue item = NAME_MAP.get(value);
		if (item == null) {
			return "";
		}
		return item.getName();
	}

	/**
	 * 项目集合
	 * 
	 * @return
	 */
	public static Collection<IntegerConstantItemValue> items() {
		return NAME_MAP.values();
	}
}
